#include <allegro.h>
#include "menu.h"
#include "deplacement.h"
void Menu(int *CarColor1,int *CarColor2,int *numMap)
{
BITMAP *Buffer;
BITMAP *car;
int j=0,k=0,l=0,m=0;
BITMAP *interface[3];
BITMAP *voiture[6];
BITMAP *voiture2[6];
BITMAP *menustage[6];
SAMPLE *son;
SAMPLE *son1;
SAMPLE *son2;
set_volume(255,255);
son=load_sample("../son/powerup.wav");
son1=load_sample("../son/hit1.wav");
son2=load_sample("../son/harp.wav");
interface[0]=load_bitmap("../img/interface0.bmp",NULL);
interface[1]=load_bitmap("../img/interface1.bmp",NULL);
interface[2]=load_bitmap("../img/interface2.bmp",NULL);
//chargement des image
voiture[0]=load_bitmap("../img/voiture0.bmp",NULL);
voiture[1]=load_bitmap("../img/voiture1.bmp",NULL);
voiture[2]=load_bitmap("../img/voiture2.bmp",NULL);
voiture[3]=load_bitmap("../img/voiture3.bmp",NULL);
voiture[4]=load_bitmap("../img/voiture4.bmp",NULL);
voiture[5]=load_bitmap("../img/voiture5.bmp",NULL);

voiture2[0]=load_bitmap("../img/voiture20.bmp",NULL);
voiture2[1]=load_bitmap("../img/voiture21.bmp",NULL);
voiture2[2]=load_bitmap("../img/voiture22.bmp",NULL);
voiture2[3]=load_bitmap("../img/voiture23.bmp",NULL);
voiture2[4]=load_bitmap("../img/voiture24.bmp",NULL);
voiture2[5]=load_bitmap("../img/voiture25.bmp",NULL);


menustage[0]=load_bitmap("../img/menustage0.bmp",NULL);
menustage[1]=load_bitmap("../img/menustage1.bmp",NULL);
menustage[2]=load_bitmap("../img/menustage2.bmp",NULL);
menustage[3]=load_bitmap("../img/menustage3.bmp",NULL);
menustage[4]=load_bitmap("../img/menustage4.bmp",NULL);
menustage[5]=load_bitmap("../img/menustage5.bmp",NULL);

Buffer=create_bitmap(SCREEN_W,SCREEN_H);
blit(interface[0],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);






while (!key[KEY_ENTER])
{
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);

if (key[KEY_DOWN])
{
j++;
play_sample(son,250,128,1000,0);
}

if (key[KEY_UP])
{
j--;
play_sample(son,250,128,1000,0);
}

if (j==3)
{
j=0;
play_sample(son1,250,128,1000,0);

}

if (j<0)
{
play_sample(son1,250,128,1000,0);
j=2;
}

blit(interface[j],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();

}
play_sample(son2,250,128,1000,0);
clear_bitmap(Buffer);
blit(voiture[0],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();
//_________________________________________________________________________________________
if (j==0)
{ 
//blit(voiture[0],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
while(!key[KEY_ENTER])
{
if (key[KEY_RIGHT])
{
k++;
play_sample(son,250,128,1000,0);
}

if (key[KEY_LEFT])
{
k--;
play_sample(son,250,128,1000,0);
}

if (k==6)
{
k=5;
play_sample(son1,250,128,1000,0);
}

if (k<0)
{
k=0;
play_sample(son1,250,128,1000,0);
}

clear_bitmap(Buffer);
blit(voiture[k],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();
}
/*
clear_bitmap(Buffer);
blit(voiture[0],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();*/


clear_bitmap(Buffer);


play_sample(son2,250,128,1000,0);
m=0;
blit(voiture2[m],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();
//_________________________________________________
while (!key[KEY_ENTER])
{readkey();


if (key[KEY_RIGHT])
{
m++;
play_sample(son,250,128,1000,0);
}

if (key[KEY_LEFT])
{
m--;
play_sample(son,250,128,1000,0);
}

if (m==6)
{
m=5;
play_sample(son1,250,128,1000,0);
}

if (m<0)
{
m=0;
play_sample(son1,250,128,1000,0);
}

clear_bitmap(Buffer);
blit(voiture2[m],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
//readkey();

}



play_sample(son2,250,128,1000,0);
}


// menu satge _______


clear_bitmap(Buffer);
blit(menustage[0],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();

while(!key[KEY_ENTER])
{


if (key[KEY_RIGHT])
{
l++;
play_sample(son,250,128,1000,0);
}


if (key[KEY_LEFT])
{
l--;
play_sample(son,250,128,1000,0);
}

if ((key[KEY_DOWN])&&((l==0)||(l==1)||(l==2)))
{
l=l+3;
play_sample(son,250,128,1000,0);
}

if ((key[KEY_UP])&&((l==3)||(l==4)||(l==5)))
{
l=l-3;
play_sample(son,250,128,1000,0);
}

if (l==6)
{
l=5;
play_sample(son1,250,128,1000,0);
}

if (l<0)
{
l=0;
play_sample(son1,250,128,1000,0);
}

blit(menustage[l],Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();
play_sample(son2,250,128,1000,0);
stop_sample(son);

play_sample(son2,250,128,1000,0);
}
destroy_bitmap(Buffer);
*numMap=k;
*CarColor1=l;
*CarColor2=m;

}
